package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.lang.Nullable;

import javax.xml.soap.Name;
import java.util.concurrent.CountDownLatch;

public class Receiver implements MessageListener {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    private CountDownLatch latch;

    public StringRedisTemplate getRedisTemplate() {
        return stringRedisTemplate;
    }

    public void setRedisTemplate(StringRedisTemplate stringRedisTemplate) {
        this.stringRedisTemplate = stringRedisTemplate;

    }

    public  Receiver() {

    }

    public Receiver(CountDownLatch latch) {
        this.latch = latch;
    }

    @Override
    public void onMessage(Message message, @Nullable byte[] bytes) {
        RedisSerializer<String> valueSerializer = stringRedisTemplate.getStringSerializer();
        String deserialize = valueSerializer.deserialize(message.getBody());

    }
}
